﻿using GalaSoft.MvvmLight.Command;
using HandyControl.Data;

namespace TroubleshootingofBeanBagAssistant.ViewModel
{
	public class ListViewViewModel : ViewModelBase<ListViewDataModel>
	{
		public static ListViewViewModel paginatioViewModel { get; set; }


		/// <summary>
		///   ListViewDataModel  所有数据
		/// </summary>
		public static List<ListViewDataModel> _totalDataList;


		/// <summary>
		/// 指令词    所有数据
		/// </summary>
		public static List<ListViewDataModel> _totalListViewDataModelDataList = new();


		/// <summary>
		///     页码
		/// </summary>
		private int _pageIndex = 1;

		/// <summary>
		///     页码
		/// </summary>
		public int PageIndex
		{
			get => _pageIndex;
#if NET40
            set => Set(nameof(PageIndex), ref _pageIndex, value);
#else
			set => Set(ref _pageIndex, value);
#endif
		}

		/// <summary>
		///     页码
		/// </summary>
		private int _pageIndexListViewDataModel = 1;

		/// <summary>
		///     页码
		/// </summary>
		public int PageIndexListViewDataModel
		{
			get => _pageIndexListViewDataModel;
#if NET40
            set => Set(nameof(PageIndex), ref _pageIndexListViewDataModel, value);
#else
			set => Set(ref _pageIndexListViewDataModel, value);
#endif
		}





		public ListViewViewModel()
		{
			try
			{

				_totalDataList = new List<ListViewDataModel>() {
				 new ListViewDataModel
							{
								Index = "等待开始自检任务",
								Timeofappearance = DateTime.Now.ToString(),
								Remark = "未开始"
							}
				};
				DataList = _totalDataList.Take(20).ToList();

				paginatioViewModel = this;

			}
			catch (Exception)
			{

			}

		}

		/// <summary>
		///     页码改变命令
		/// </summary>
		public RelayCommand<FunctionEventArgs<int>> PageUpdatedCmd => new(PageUpdated);

		//public RelayCommand<string> SearchCmd => new(Search);

		//private void Search(string key)
		//{

		//	////Growl.Info(key);

		//	DataList = _totalDataList.Where(a => a.DisplayName.Contains(key)).ToList();

		//}



		/// <summary>
		/// 指令词
		/// </summary>
		public RelayCommand<FunctionEventArgs<int>> PageUpdatedCmdListViewDataModel => new(PageUpdatedInstruction);



		/// <summary>
		///     页码改变
		/// </summary>
		private void PageUpdated(FunctionEventArgs<int> info)
		{

			DataList = _totalDataList.Skip((info.Info - 1) * 20).Take(20).ToList();
			//Global.voiceSearch.UpdateVoiceSearchUI();
		}

		/// <summary>
		///指令词页面更改
		/// </summary>
		private void PageUpdatedInstruction(FunctionEventArgs<int> info)
		{

			DataList1 = _totalListViewDataModelDataList.Skip((info.Info - 1) * 5).Take(5).ToList();

		}




		///// <summary>
		/////     修改全部选中
		///// </summary>
		//public List<ListViewDataModel> UpdatedStatus()
		//{
		//	//try
		//	//{
		//	//	foreach (ListViewDataModel item in _totalDataList)
		//	//	{
		//	//		item.IsChecked = true;
		//	//	}
		//	//	DataList = _totalDataList.Take(20).ToList();
		//	//	return _totalDataList;
		//	//}
		//	//catch (Exception ex)
		//	//{
		//	//	LogWriter.Log("ListViewViewModel Exception", ex.Message);
		//	//}

		//	//return _totalDataList;

		//}



		/// <summary>
		///     获取所有的Windows 应用信息
		/// </summary>
		public List<ListViewDataModel> GetDataList()
		{

			return _totalDataList;
		}



		/// <summary>
		///     添加数据  Windows 应用的
		/// </summary>
		public List<ListViewDataModel> AddDataList(ListViewDataModel ListViewDataModel)
		{
			try
			{
				_totalDataList.Add(ListViewDataModel);
				DataList = _totalDataList.Take(20).ToList();
				return _totalDataList;
			}
			catch (Exception ex)
			{

				//LogWriter.Log(ex, ex.Message);
				return _totalDataList;

			}

		}

		/// <summary>
		///     删除数据  指令词   的
		/// </summary>
		public void DelDataList()
		{
			try
			{
				_totalDataList = new List<ListViewDataModel>();
				DataList = new List<ListViewDataModel>();

			}
			catch (Exception ex)
			{




			}

		}


		/// <summary>
		///     添加数据  指令词   的
		/// </summary>
		public List<ListViewDataModel> AddListViewDataModelDataList(ListViewDataModel ListViewDataModel)
		{
			try
			{
				_totalListViewDataModelDataList.Add(ListViewDataModel);
				DataList1 = _totalListViewDataModelDataList.Take(5).ToList();
				return _totalListViewDataModelDataList;
			}
			catch (Exception ex)
			{

				//LogWriter.Log(ex, ex.Message);
				return _totalListViewDataModelDataList;

			}

		}





	}
}
